package com.studies.mycenter.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.studies.common.R.R;
import com.studies.mycenter.pojo.Activity;
import com.studies.mycenter.pojo.ActivityRecord;
import com.studies.mycenter.service.ActivityRecordService;
import com.studies.mycenter.service.ActivityService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * <p>
 * 研学风采 前端控制器
 * </p>
 *
 * @author 研学活动后台
 * @since 2019-12-24
 */
@Api(tags="活动模块")
@CrossOrigin //跨域
@RestController
@RequestMapping("/mycenter/activity-record")
public class ActivityRecordController {

    @Autowired
    private ActivityRecordService activityRecordService;
    @ApiOperation(value = "分页研学风采列表")
    @GetMapping(value = "{page}/{limit}")
    public R selectPage(@ApiParam(name = "page", value = "当前页码", required = true)
                        @PathVariable Long page,

                        @ApiParam(name = "limit", value = "每页记录数", required = true)
                        @PathVariable Long limit){

        Page<ActivityRecord> pageParam = new Page<ActivityRecord>(page, limit);

        Map<String, Object> map = activityRecordService.selectRecordPage(pageParam);

        return  R.ok().data(map);
    }

    @ApiOperation(value = "根据ID删除分采的图片")
    @GetMapping(value = "{id}")
    public boolean deleteActivityRecord(@ApiParam(name = "id", value = "当前id", required = true) @PathVariable Integer id){
        boolean b = activityRecordService.removeById(id);
        return b;
    }

    @ApiOperation(value = "添加分采的图片")
    @PostMapping
    public R addActivityRecord(@ApiParam(name = "ActivityRecord", value = "ActivityRecord对象", required = true) @PathVariable ActivityRecord activityRecord){
        activityRecordService.save(activityRecord);
        return R.ok();
    }
}

